﻿using ARNative;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NRemedy.MVC.UI
{
    public class MenuDataJsonModel
    {
        public string v { get; set; }
        public string t { get; set; }

        public static MenuDataJsonModel Create(AREntry entry, uint vid, uint tid)
        {
            if (entry == null)
                return null;
            MenuDataJsonModel model = new MenuDataJsonModel();

            var flv = entry.FieldValues.FirstOrDefault(fv => fv.FieldId == vid);
            if (flv == null)
                throw new MemberAccessException(vid + " could not be found in the returned entry.");
            model.v = flv.Value == null ? null : flv.Value.ToString();

            var flt = entry.FieldValues.FirstOrDefault(fv => fv.FieldId == tid);
            if (flt == null)
                throw new MemberAccessException(tid + " could not be found in the returned entry.");
            model.t = flt.Value == null ? null : flt.Value.ToString();

            return model;
        }

    }

}
